﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "AddPlatformPages.h"
#include "GbmpUiPlatformCommandIds.h"
#include "GcmpUiDebugCommandNames.h"
#include "IPublishConfig.h"
#include "IRibbon.h"
#include "IRibbonPage.h"
#include "IRibbonGroup.h"
#include "IApplication.h"
#include "IMainWindow.h"
#include "ICommandButtonDefinition.h"
#include "IPageHandler.h"
#include "GcmpCommandState.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"
using namespace gcmp;

namespace
{
    class ManagementPageHandler : public IPageHandler
    {
    public:
        ManagementPageHandler(){}
        virtual ~ManagementPageHandler() {}
       
    public:
        virtual bool IsVisible() const override
        {
            return GcmpCommandState::IsInProjectEnvironment() && !GcmpCommandState::IsInAnimationEnvironment();
        }
        virtual bool IsEnabled() const override
        {
            return true;
        }
    };
}

void AddPlatformPages::AddPageManagement()
{
    bool isInHouseMode = false;
    const IConfigRecord* pInHouseModeConfigRecord = IPublishConfig::GetConfigRecord(PublishConfigRecordNames::InHouseMode);
    if (pInHouseModeConfigRecord != nullptr && pInHouseModeConfigRecord->IsInternalIdentifyCodeValue())
    {
        isInHouseMode = true;
    }

    OwnerPtr<IRibbonPage> opPage = IRibbonPage::Create(ID_PAGE_MANAGEMENT, GBMP_TR(L"String_Ribbon_Panel_Manage"));
    DBG_WARN_AND_RETURN_VOID_UNLESS(opPage, L"opPage为空",L"GDMPLab",L"2024-03-30");
    opPage->SetPageHandler(TransferOwnership(NEW_AS_OWNER_PTR(ManagementPageHandler)));

    // 设置Group
    {
        const std::wstring groupId(L"gmManagementGroup");
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"设置"));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");

        // 图形样式（项目）
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_PROJECT_GRAPHICS_STYLE, GBMP_TR(L"对象样式"), GBMP_TR(L"对象样式"), ID_CMD_PROJECT_GRAPHICS_STYLE, L":/images/management/对象样式01.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        // 捕捉
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_SNAP_SETTING, GBMP_TR(L"捕捉设置"), GBMP_TR(L"捕捉设置"), ID_CMD_SNAP_SETTING, L":/images/management/捕捉设置.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        // 线型管理
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_LINE_TYPE, GBMP_TR(L"线型管理"), GBMP_TR(L"线型管理"), ID_CMD_LINE_TYPE, L":/images/management/线型管理.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        // 云线样式管理
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_REVCLOUD_STYLES, GBMP_TR(L"云线样式"), GBMP_TR(L"云线样式"), ID_CMD_REVCLOUD_STYLES, L":/images/management/线型管理.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        opPage->AddGroup(TransferOwnership(opGroup));
    }

    // 插件Group
    {
        if (isInHouseMode)
        {
            const std::wstring groupId(L"gmAddinGroup");
            OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"插件"));
            DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");

            {
                OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_ADDIN_MGR, GBMP_TR(L"插件管理"), GBMP_TR(L"插件管理"), ID_CMD_ADDIN_MGR, L":/images/addin.png");
                opGroup->AddButton(TransferOwnership(opButtonDef));
            }

            opPage->AddGroup(TransferOwnership(opGroup));
        }
    }

    IRibbon* pRibbon = IMainWindow::GetMainWindow()->GetRibbon();
    DBG_WARN_AND_RETURN_VOID_UNLESS(pRibbon, L"pRibbon为空",L"GDMPLab",L"2024-03-30");

    pRibbon->AddPage(TransferOwnership(opPage));
}
